<%@ include file="/WEB-INF/views/include.jsp"%>
<%@ page session="false"%>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Manage User</title>
</head>
<body>
	<input id="size" name="size" type="hidden" value="${size}" />
	<input type="text" size="4" name="maxPageItems" value="${pageItems}"
		onChange="this.form.submit();">
	<pg:pager items="${size}" url="manager" index="center"
		maxPageItems="${pageItems}" maxIndexPages="10" isOffset="<%= true %>"
		export="offset,currentPageNumber=pageNumber" scope="request">
		<%-- keep track of preference --%>
		<pg:param name="style" />
		<pg:param name="position" />
		<pg:param name="index" />
		<pg:param name="maxPageItems" />
		<pg:param name="maxIndexPages" />

		<%-- save pager offset during form changes --%>
		<input type="hidden" name="pager.offset" value="<%=offset%>">


		<jsp:include page="/WEB-INF/views/paging.jsp" flush="true" />

		<table class="search">
			<tr>
				<th><fmt:message key="user.form.id" />
				</th>
				<th><fmt:message key="user.form.fullname" />
				</th>
				<th><fmt:message key="user.form.username" />
				</th>
				<th><fmt:message key="user.form.email" />
				</th>
				<th><fmt:message key="user.form.role" />
				</th>
				<th><fmt:message key="user.form.Registered" />
				</th>
				<th><fmt:message key="user.form.Action" />
				</th>
			</tr>
			<c:forEach items="${users}" var="user">
				<pg:item>
					<tr>
						<c:url var="editUrl" value="/bo/users/edit-user">
							<c:param name="id" value="${user.id}" />
						</c:url>
						<sec:authorize access="hasRole('ROLE_ADMIN')">
							<c:url var="deleteUrl" value="/bo/users/delete-user" />
							<form id="deleteForm${user.id}" action="${deleteUrl}"
								method="POST">
								<input id="id" name="id" type="hidden" value="${user.id}" />
							</form>
						</sec:authorize>

						<td>${user.id}</td>
						<td>${user.firstName} ${user.lastName}</td>
						<td>${user.username}</td>
						<td>${user.email}</td>
						<td>${user.role}</td>
						<td><fmt:formatDate value="${user.createdDate}"
								pattern="yyyy-MM-dd hh:mm:ss" /></td>
						<td><a href='<c:out value="${editUrl}"/>'><fmt:message
									key="button.edit" />
						</a> <sec:authorize access="hasRole('ROLE_ADMIN')">
								<a href="javascript:jQuery('#deleteForm${user.id}').submit();"><fmt:message
										key="button.delete" />
								</a>
							</sec:authorize></td>
					</tr>
				</pg:item>
			</c:forEach>
		</table>
	</pg:pager>
</body>
</html>
